
import 'package:flutter/material.dart';
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_easyrefresh/material_footer.dart';
import 'package:flutter_module/view_model/query_model.dart';
import 'package:flutter_module/widget/provider_widget.dart';
import 'package:flutter_module/widget/tap_appbar.dart';
import 'package:flutter_screenutil/screenutil.dart';

import '../amap.dart';

class GongChengGuanLi extends StatefulWidget {
  @override
  _GongChengGuanLi createState() => _GongChengGuanLi();
}

class _GongChengGuanLi extends State<GongChengGuanLi> {
  Map<String,String> wgfgsMap = {
    "1":"网管一分",
    "2":"网管二分",
    "3":"网管三分",
    "4":"网管四分",
    "5":"中水分公司",
  };

  Map<String,String> xmbMap = {
    "1":"一项",
    "2":"二项",
    "3":"三项",
    "4":"四项",
  };

  Map<String,String> gcztMap = {
    "working":"施工中",
    "completed":"已完成",
  };

  Map<String,String> xzMap = {
    "1":"雨水",
    "2":"污水",
    "3":"雨水支线",
    "4":"污水支线",
    "5":"雨污合流",
    "6":"雨水篦子",
    "8":"盖板",
    "7":"其他",
  };

//  <option  value="DN100">DN100</option>
//  <option  value="DN200">DN200</option>
//  <option  value="DN300">DN300</option>
//  <option  value="DN400">DN400</option>

//  <option  value="QT">其他</option>
  Map<String,String> mmList = {
  };

  Map<String,String> sgyyList = {
    "2": "线管老化、造成路面或步道未塌陷",
    "4":"盖板老化、造成路面或步道塌陷",
    "5":"盖板老化、造成路面或步道未塌陷",
    "3":"检查井井墙倒塌",
    "7":"雨水篦子倒塌",
    "6":"外单位施工破坏",
    "1":"管线老化、造成路面或步道塌陷",
  };

  Map<String,String> sgfeList = {
    "1":"明开槽换管",
    "12":"非开挖修复（插管）",
    "10":"非开挖修复（喷涂）",
    "13":"非开挖修复（紫外固化）",
    "14":"非开挖修复（螺旋缠绕）",
    "5":"塌点位置回填，非开挖修复	",
    "3":"锚喷竖井顶管",
    "4":"锚喷竖井插管",
    "6":"拉管",
    "7":"砌筑检查井",
    "8":"砌筑雨水口",
    "9":"更换盖板",
    "2":"化学注浆"
  };
  List list;
  var wgfgsValue;


  var value;

  var xmbValue;
  var gcztValue;
  var xzValue;
  var mmValue;
  var sgyyValue;
  var sgfeValue;
  var sDate = " ";
  var eDat = "";
  String pName = "";
  QueryModel queryModel= new QueryModel();
  Map<String,String> queryMap;
  @override
  void initState() {
    // TODO: implement initState

    mmListGet();

  }

  void mmListGet() {
    for (int i = 1; i < 29; i++) {
      mmList["DN$i" + "00"] = "DN$i" + "00";
    }
    mmList["QT"] = "其他";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: TapAppBar(TapViewBar(Text("工程查询"), icon: Icon(Icons.arrow_back)),
          Size.fromHeight(ScreenUtil().setHeight(80))),
      body: ProviderWidget<QueryModel>(
        model: QueryModel(),onModelInit: (model){
        model.getHttpData().then((value){
          list=model.data;
        });
      }, builder: (context, model, child) {
        return EasyRefresh(

            controller: model.controller,
            footer: MaterialFooter(),
            enableControlFinishLoad: true,
            onLoad:model.onLoad,
            bottomBouncing: true,
            child: SingleChildScrollView(
              child: Column(
                children: <Widget>[
                  getItem("网管分公司", wgfgsMap),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getInPutName(),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  Container(
                    color: Colors.white,
                    child: getDate("开始时间"),
                  ),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  Container(
                    color: Colors.white,
                    child: getDate2("结束时间"),
                  ),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getItem2("项目部 ", xmbMap),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getItem3("工程状态", gcztMap),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getItem4("性质", xzMap),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getItem5("管径(mm)", mmList),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getItem6("事故原因", sgyyList),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getItem7("施工方案", sgfeList),
                  SizedBox(height: 1,
                    width: ScreenUtil().setWidth(700),
                    child: Container(color: Colors.black12,),),
                  getQuery(model),
                  getWrap(),

                ],
              ),
            ));
      },
      ),
    );
  }
  List<Widget> getListItem(){
    return list.map((value){
      return Container(
//        color: Colors.white,
        margin: EdgeInsets.only(left: 10, right: 10,top: 10),
        padding: EdgeInsets.only(left: 20, top: 10),
        decoration: new BoxDecoration(
          //背景
          color: Colors.white,
          //设置四周圆角 角度
          borderRadius: BorderRadius.all(Radius.circular(4.0)),
          //设置四周边框
//          border: new Border.all(width: 1, color: Colors.red),
        ),
        child: Column(
          children: <Widget>[
            getListItemData("管网分公司:", value[0]),
            SizedBox(height: 10,),
            getListItemData("拟定工程名称:", value[1]),
            SizedBox(height: 10,),
            getListItemData("工程状态:", value[2]),
            SizedBox(height: 10,),
            getListItemData("事件发生地点:", value[3]),
            SizedBox(height: 10,),
            getListItemData("抢险负责人:", value[4]),
            SizedBox(height: 10,),
            getListItemData("项目部:", value[5]),
            SizedBox(height: 10,),
            getListItemData("处置开始时间:", value[6]),
            SizedBox(height: 10,),
            getListItemData("处置完成时间:", value[7]),
            SizedBox(height: 10,),
            getListItemData("实施时长:", value[8]),
            SizedBox(height: 10,),
            getListItemData("性        质:", value[9]),
            SizedBox(height: 10,),
            getListItemData("管        径:", value[10]),
            SizedBox(height: 10,),
            getListItemData("数        量:", value[11]),
            SizedBox(height: 10,),
            getListItemData("事故原因:", value[12]),
            SizedBox(height: 10,),
            getListItemData("施工方案:", value[13]),
            SizedBox(height: 10,),
            getListItemData("区        域:", value[14]),
            SizedBox(height: 10,),
            getListItemData("备        注:", value[15]),
            SizedBox(height: 10,),
          ],
        ),
      );

    }).toList();
  }
  Widget getListItemData(String name,String data){
    return Row(
      children: <Widget>[
        Expanded(child: Text(name,style: TextStyle(fontWeight: FontWeight.bold),),flex: 2,),
        SizedBox(width: 5,),
        Expanded(child: Text(data,style: TextStyle(color: Colors.black54),),flex: 5,)
      ],
    );
  }
  Widget getDate(String sDate) {
    return
      Container(
        height:  ScreenUtil().setHeight(80),
        child: FlatButton(
            onPressed: () {
              DatePicker.showDatePicker(context,
                  showTitleActions: true,
                  minTime: DateTime(2018, 3, 5),
                  maxTime: DateTime(2030, 6, 7),
                  onChanged: (date) {},
                  onConfirm: (date) {
                    setState(() {
                      this.sDate = date.toString().substring(0, 10);
                    });
                  },
                  currentTime: DateTime.now(),
                  locale: LocaleType.zh);
            },
            child: Container(
              alignment: Alignment.center,

              margin: EdgeInsets.only(left: 15, right: 30),
              child: Row(
                children: <Widget>[
                  Expanded(child: Text(sDate,textAlign: TextAlign.right,), flex: 2,),
                  SizedBox(
                    width: 5,
                  ),
                  Expanded(child: Text(this.sDate,style: new TextStyle(fontSize:12,color: const Color(0xff888888)),), flex: 6,)

                ],
              ),
            )),
      );
  }

  Widget getDate2(String eDate) {
    return  Container(
      height: ScreenUtil().setHeight(80),
      child: FlatButton(
          onPressed: () {
            DatePicker.showDatePicker(context,
                showTitleActions: true,
                minTime: DateTime(2018, 3, 5),
                maxTime: DateTime(2030, 6, 7),
                onChanged: (date) {},
                onConfirm: (date) {
                  setState(() {
                    this.eDat = date.toString().substring(0, 10);
                  });
                },
                currentTime: DateTime.now(),
                locale: LocaleType.zh);
          },
          child: Container(
            alignment: Alignment.center,

            margin: EdgeInsets.only(left: 15, right: 30),
            child: Row(
              children: <Widget>[
                Expanded(child: Text(eDate,textAlign: TextAlign.right,), flex: 2,),
                SizedBox(
                  width: 5,
                ),
                Expanded(child: Text(this.eDat,style: new TextStyle(fontSize:12,color: const Color(0xff888888)),), flex: 6,)

              ],
            ),
          )),
    )
      ;
  }

  Widget getItem(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign: TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value,style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: wgfgsValue,
            onChanged: (value) {
              setState(() {
                this.wgfgsValue = value;
              });
            }));
  }
  Widget getItem2(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign:TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton2(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton2(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value,style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: xmbValue,
            onChanged: (value) {
              setState(() {
                this.xmbValue = value;
              });
            }));
  }
  Widget getItem3(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign:TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton3(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton3(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value,style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: gcztValue,
            onChanged: (value) {
              setState(() {
                this.gcztValue = value;
              });
            }));
  }
  Widget getItem4(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign:TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton4(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton4(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value,style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: xzValue,
            onChanged: (value) {
              setState(() {
                this.xzValue = value;
              });
            }));
  }
  Widget getItem5(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign:TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton5(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton5(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value,style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: mmValue,
            onChanged: (value) {
              setState(() {
                this.mmValue = value;
              });
            }));
  }
  Widget getItem6(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign:TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton6(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton6(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value, style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: sgyyValue,
            onChanged: (value) {
              setState(() {
                this.sgyyValue = value;
              });
            }));
  }
  Widget getItem7(String title, Map<String, String> list) {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(
            child: Text(title,textAlign:TextAlign.right,),
            flex: 2,
          ),
          SizedBox(
            width: 5,
          ),
          Expanded(
            child: getDownButton7(list),
            flex: 6,
          )
        ],
      ),
    );
  }

  Widget getDownButton7(Map<String, String> list) {
    var list1 = List<DropdownMenuItem>();
    list.forEach((String key, String value) {
      list1.add(DropdownMenuItem(child: Text(value, style: new TextStyle(fontSize:12,color: const Color(0xff888888))), value: key));
    });
    return DropdownButtonHideUnderline(
        child: DropdownButton(
            items: list1,
            value: sgfeValue,
            onChanged: (value) {
              setState(() {
                this.sgfeValue = value;
              });
            }));
  }

  Widget getInPutName() {
    return Container(
      color: Colors.white,
      alignment: Alignment.center,
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(child: Text("工程名称",textAlign: TextAlign.right,), flex: 2,),
          Expanded(child: TextField(
            decoration: InputDecoration(
              //  labelText: sp.getUserInfo("num").toString(),
              fillColor: Colors.white,
              filled: true,
              border: InputBorder.none,
              hintText: "",

            ),
            onChanged: (value) {
              pName = value;
            },
            style: new TextStyle(fontSize:12,color: const Color(0xff888888)),
          ), flex: 6,)

        ],
      ),
    );
  }


  Widget getQuery(QueryModel model) {
    return Container(
      // color: Colors.black12,
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 10),
      height: ScreenUtil().setHeight(80),
      padding: EdgeInsets.only(left: 30, right: 30),
      child: Row(
        children: <Widget>[
          Expanded(child:
          RaisedButton(
            onPressed: () {
              queryMap=Map();
              queryMap["buildPlan"]=sgfeValue;
              queryMap["department"]=xmbValue;
              queryMap["eventReason"]=sgyyValue;
              queryMap["eventType"]=xzValue;
              queryMap["jssj"]=eDat;
              queryMap["kssj"]=sDate;
              queryMap["organization"]=wgfgsValue;
              queryMap["pipeRadius"]=mmValue;
              queryMap["projectName"]=pName;
              queryMap["projectStatus"]=gcztValue;
              model.map=queryMap;
              model.query = false;
              model.getHttpData(data: queryMap);
            },
            child: Text("查询")
            ,
            textColor: Colors.white,
            color: Theme
                .of(context)
                .primaryColor,

            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
              // side: BorderSide(color: Colors.red)
            ),),
            flex: 1,),
          Text("   "),
          Expanded(child:
          RaisedButton(
            onPressed: () {
//              Navigator.of(context).push( MaterialPageRoute(builder: (context)=>AmapPage(queryMap)));
            },
            child: Text("查看地图")
            ,
            textColor: Colors.white,
            color: Theme
                .of(context)
                .primaryColor,

            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
              // side: BorderSide(color: Colors.red)
            ),),
            flex: 1,)

        ],
      ),
    );
  }

  Widget getWrap() {
    if(list==null){
      return
        Text(" ");
    }else{
      return Container(
//        padding: EdgeInsets.only(left: 30),
        child: Wrap(
          spacing: 1,
          children: getListItem(),
        ),
      );
    }

  }


}

